import { request } from './request.js'
request.defaultData.baseUrl = 'http://cyjs.pzhkj.cn/'

export function getFavCpCategoryList() {
  return new Promise((resolve, reject) => {
    request
      .ajax({
        path: 'api/customers/getFavCpCategoryList',
        method: 'POST',
        afterAjax: res => {
          resolve(res)
        },
      })
      .catch(err => {
        reject(err)
      })
  })
}

export function getRecommendPlan() {
  return new Promise((resolve, reject) => {
    request
      .ajax({
        path: 'api/customers/recommendPlan',
        method: 'POST',
        afterAjax: res => {
          resolve(res)
        },
      })
      .catch(err => {
        reject(err)
      })
  })
}

export function getFavList({ caipiao_id, qihao }) {
  return new Promise((resolve, reject) => {
    request
      .ajax({
        path: 'api/customers/favList',
        method: 'POST',
        data: {
          caipiao_id,
          qihao,
        },
        afterAjax: res => {
          resolve(res)
        },
      })
      .catch(err => {
        reject(err)
      })
  })
}

export function getRecList({
  caipiao_id,
  qihao,
  maQuantity,
  maChu,
  page,
  searchKey,
}) {
  return new Promise((resolve, reject) => {
    request
      .ajax({
        path: 'api/optional/getData',
        method: 'POST',
        data: {
          caipiao_id,
          qihao,
          maQuantity,
          maChu,
          page,
          // searchKey
        },
        afterAjax: res => {
          resolve(res)
        },
      })
      .catch(err => {
        reject(err)
      })
  })
}
